extends Node

@onready var pauser_audio_stream_player: AudioStreamPlayer = $PauserAudioStreamPlayer
@onready var un_pauser_audio_stream_player: AudioStreamPlayer = $UnPauserAudioStreamPlayer
@onready var 菜单: Sprite2D = $菜单
@onready var 暂停: TouchScreenButton = $暂停

func _ready() -> void:
	菜单.visible = false
	$菜单/play.pressed.connect(_on_play_pressed)
	暂停.pressed.connect(_on_pause_pressed)
	pass


func _on_pause_pressed():
	print("按下暂停")
	pauser_audio_stream_player.play()
	get_tree().paused = true
	# Input.action_press("ui_cancel")
	菜单.visible = true
	暂停.visible = false

func _on_play_pressed():
	# Input.action_press("ui_cancel")
	un_pauser_audio_stream_player.play()
	get_tree().paused = false

	菜单.visible = false
	暂停.visible = true




# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	if Input.is_action_just_pressed("ui_cancel"):
		var is_pause = get_tree().paused
		print("模拟取消,当前是否暂停",is_pause)
		# 当前是暂停状态，就开始游戏，反之暂停
		if is_pause: 
			_on_play_pressed()
		else : 
			_on_pause_pressed()
		# get_tree().paused = not is_pause


# # Called every frame. 'delta' is the elapsed time since the previous frame.
# func _process(delta: float) -> void:
# 	pass
# 	# if Input.is_action_just_pressed("ui_cancel"):
# 	# 	var is_pause = get_tree().paused
# 	# 	print("模拟取消,当前是否暂停",is_pause)
# 	# 	if is_pause: 
# 	# 		un_pauser_audio_stream_player.play()
# 	# 		get_tree().paused = false
# 	# 	else : 
# 	# 		pauser_audio_stream_player.play()
# 	# 		get_tree().paused = true
# 	# 	# get_tree().paused = not is_pause
